# -*- coding:utf-8 -*-
from flask import request, jsonify, abort
from com.zzh.bigSearch.bigSearchDao import BigSearch
from flask_cors import CORS
from . import app

CORS(app, supports_credentials=True)
__author__ = "Prince_CHEN"


@app.route('/itemBigSearch', methods=['POST'])
def itemBigSearch():
    if not request.json:
        abort(400)

    try:
        keyword = request.json['keyword']
    except:
        return jsonify({"message": {"code": 0, "status": "缺少必要参数"}})
    try:
        result, count = BigSearch().itemBigSearch(keyword)

        if result == -200:
            return jsonify({"message": {"code": 0, "status": "Database Exception: -200"}})
        elif result:
            return jsonify({"total":count, "info": result, "message": {"code": 1, "status": "success"}})
        else:
            return jsonify({"message": {"code": 0, "status": "No such data!"}})
    except Exception,e:
        return jsonify({"info":[],"message": {"code": 0, "status": "No such data!"}})